//
//  ReviewCell.swift
//  appstore
//
//  Created by llbt-sk on 2019/11/8.
//  Copyright © 2019 Roy. All rights reserved.
//

import UIKit

class ReviewCell: UITableViewCell,UICollectionViewDataSource,UICollectionViewDelegate {
    
    let GameReviewCollectionCellIdentifier = "GameReviewCollectionCellIdentifier"
    
    let data: [String] = [
        "cover_detail1",
        "cover_detail2",
        "cover_detail"
    ]
    
    lazy var flowLayout:CommonCollectionFlowLayout = {
        let flowLayout = CommonCollectionFlowLayout()
        flowLayout.minimumLineSpacing = 10.0
        flowLayout.minimumInteritemSpacing = 0.0
        flowLayout.scrollDirection = .horizontal
        flowLayout.sectionInset = UIEdgeInsets(top: 0.0, left: 20.0, bottom: 0.0, right: 20.0)
        flowLayout.itemSize = CGSize(width: ScreenWidth - 40.0, height: 155.0)
        return flowLayout
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.initView()
    }
    
    func initView() -> Void {
        
        let headerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: ScreenWidth, height: 42.0))
        self.contentView.addSubview(headerView)
        
        let topicTitleLabel = UILabel()
        topicTitleLabel.font = UIFont.systemFont(ofSize: 22.0, weight: .medium)
        topicTitleLabel.textColor = UIColor.black
        topicTitleLabel.text = "Review"
        headerView.addSubview(topicTitleLabel)
        topicTitleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(13.0)
            make.left.equalTo(20.0)
            make.width.equalTo(200.0)
            make.height.equalTo(24.0)
        }
        
        let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: flowLayout)
        collectionView.dataSource = self
        collectionView.delegate = self
        collectionView.backgroundColor = .white
        collectionView.showsHorizontalScrollIndicator = false
        self.contentView.addSubview(collectionView)
        collectionView.snp.makeConstraints { (make) in
            make.top.equalTo(headerView.snp.bottom).offset(0.0)
            make.bottom.left.right.equalTo(0.0)
        }
        collectionView.register(ReviewCollectionViewCell.self, forCellWithReuseIdentifier: GameReviewCollectionCellIdentifier)
        
    }
    
    // UICollectionViewDataSource
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return data.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: GameReviewCollectionCellIdentifier, for: indexPath) as! ReviewCollectionViewCell
        cell.coverImageView.image = UIImage(named: data[indexPath.row])
        return cell
    }
    
    // UICollectionViewDelegate
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
